package com.coldworks.coldjoke.ui;

import com.coldworks.coldjoke.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.LinearLayout;

public class MenuNavView extends LinearLayout {

	private CheckedTextView navJoke;
	private CheckedTextView navTopic;
	private CheckedTextView navJudge;
	private CheckedTextView navPost;

	private OnNavSelectListner listenner;

	public MenuNavView(Context context) {
		super(context);
		setUpViews(context);
	}

	public MenuNavView(Context context, AttributeSet attrs) {
		super(context, attrs);
		setUpViews(context);
	}

	public MenuNavView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		setUpViews(context);
	}

	private void setUpViews(final Context context) {
		LinearLayout view = (LinearLayout) LayoutInflater.from(context)
				.inflate(R.layout.menu_nav, this, false);
		navJoke = (CheckedTextView) view.findViewById(R.id.nav_joke);
		navTopic = (CheckedTextView) view.findViewById(R.id.nav_topic);
		navJudge = (CheckedTextView) view.findViewById(R.id.nav_judge);
		navPost = (CheckedTextView) view.findViewById(R.id.nav_post);

		navJoke.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (navJoke.isChecked()) {
					listenner.onNavClose();
				} else {
					listenner.onNavJokeClick();
					navJoke.setChecked(true);
					navTopic.setChecked(false);
					navJudge.setChecked(false);
					navPost.setChecked(false);
				}
			}
		});

		navTopic.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (navTopic.isChecked()) {
					listenner.onNavClose();
				} else {
					listenner.onNavTopicClick();
					navJoke.setChecked(false);
					navTopic.setChecked(true);
					navJudge.setChecked(false);
					navPost.setChecked(false);
				}
			}
		});
		navJudge.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (navJudge.isChecked()) {
					listenner.onNavClose();
				} else {
					listenner.onNavJudgeClick();
					navJoke.setChecked(false);
					navTopic.setChecked(false);
					navJudge.setChecked(true);
					navPost.setChecked(false);
				}
			}
		});
		navPost.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (navPost.isChecked()) {
					listenner.onNavClose();
				} else {
					listenner.onNavPostClick();
					navJoke.setChecked(false);
					navTopic.setChecked(false);
					navJudge.setChecked(false);
					navPost.setChecked(true);
				}
			}
		});

		addView(view);
		setOrientation(VERTICAL);
	}

	public void setOnNavSelectListener(OnNavSelectListner listner) {
		this.listenner = listner;
	}

	public interface OnNavSelectListner {
		void onNavJokeClick();

		void onNavTopicClick();

		void onNavJudgeClick();

		void onNavPostClick();

		void onNavClose();
	}

}
